package com.example.v3admin.common.exception;
import com.example.v3admin.common.result.BusinessException;
import com.example.v3admin.common.result.ResultCode;

import com.example.v3admin.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {


        /*
         * 处理系统异常
         * 兜底异常处理，处理未被捕获的异常
         */

            @ExceptionHandler(BusinessException.class)
            @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
            public <T> Result<T> handleNullPointerException(BusinessException e) {
                log.error(e.getMessage(), e);
                if(e.getResultCode()!=null){
                    return Result.failed(e.getResultCode());

                }
                return Result.failed("系统异常:" + e.getMessage());
            }
}
